package com.sunplus.system.registration.controller;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.sunplus.system.registration.domain.PortalArticletype;
import com.sunplus.system.registration.service.IPortalArticletypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sunplus.common.annotation.Log;
import com.sunplus.common.core.controller.BaseController;
import com.sunplus.common.core.domain.AjaxResult;
import com.sunplus.common.enums.BusinessType;
import com.sunplus.common.utils.poi.ExcelUtil;

/**
 * 文章类别Controller
 * 
 * @author sunplus
 * @date 2021-03-25
 */
@RestController
@RequestMapping("/registration/articletypeMgr")
public class PortalArticletypeController extends BaseController
{
    @Autowired
    private IPortalArticletypeService portalArticletypeService;

    /**
     * 查询文章类别列表
     */
//    @PreAuthorize("@ss.hasPermi('registration:articletypeMgr:list')")
    @PostMapping("/listPain")
    public AjaxResult list(PortalArticletype portalArticletype)
    {
        startPage();
        List<PortalArticletype> list = portalArticletypeService.selectPortalArticletypeList(portalArticletype);
        JSONObject data = getDataTable(list);
        data.put("ButtonRight", "add,edit,del,view");
        return AjaxResult.success(data);
    }



    /**
     * 获取文章类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('registration:articletypeMgr:query')")
    @GetMapping(value = "/{pid}")
    public AjaxResult getInfo(@PathVariable("pid") String pid)
    {
        return AjaxResult.success(portalArticletypeService.selectPortalArticletypeById(pid));
    }

    /**
     * 新增文章类别
     */
//    @PreAuthorize("@ss.hasPermi('registration:articletypeMgr:add')")
    @Log(title = "文章类别", businessType = BusinessType.INSERT)
    @PostMapping("/Add")
    public AjaxResult add(PortalArticletype portalArticletype)
    {
        return toAjax(portalArticletypeService.insertPortalArticletype(portalArticletype));
    }

    /**
     * 获取按钮
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/GetButtonRight")
    public AjaxResult getButtonRight() throws Exception {
        return AjaxResult.success((Object) "<button class=\"layui-btn layuiadmin-btn-list\" data-type=\"add\">添加</button><button class=\"layui-btn layuiadmin-btn-list\" data-type=\"del\">删除</button>");
    }
    /**
     * 修改文章类别
     */
//    @PreAuthorize("@ss.hasPermi('registration:articletypeMgr:update')")
    @Log(title = "文章类别", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit( PortalArticletype portalArticletype)
    {
        return toAjax(portalArticletypeService.updatePortalArticletype(portalArticletype));
    }

    /**
     * 删除文章类别
     */
//    @PreAuthorize("@ss.hasPermi('registration:articletypeMgr:remove')")
    @Log(title = "文章类别", businessType = BusinessType.DELETE)
	@PostMapping("/BatchDelete")
    public AjaxResult remove(@RequestParam  String[] ids)
    {
        return toAjax(portalArticletypeService.deletePortalArticletypeByIds(ids));
    }
}
